package com.example.object.screen;

import android.content.Context;
import android.util.Log;

import com.example.bounce.R;
import com.example.globject.GLSquare;
import com.example.motion.Movable;
import com.example.object.GameShape;
import com.example.shape.Square;

import org.jbox2d.common.Vec2;

/**
 * Created by Lucas on 06/06/13.
 */
public class SignShape extends GameShape implements Movable{

    /**
     * The square to calculate is a sign is touched
     */
    private Square _square;
    /**
     * The opengl object to draw
     */
    private GLSquare _glSquare;
    /**
     * The text to write on the screen
     */
    private String _text;
    /**
     * The debug TAG
     */
    private final String TAG = "SignShape";

    /**
     * The constrcutor
     * @param context The context of the application
     * @param xCenter the x coordinate of the origin point
     * @param yCenter the y coordinate of the origin point
     * @param height the height of the sign
     * @param width the width of the sign
     * @param text the text of the sign
     * @param action the action to execute after touching a sign
     */
    public SignShape(Context context, float xCenter, float yCenter,
                                      float height, float width,
                                      String text,
                                      int action){

        Log.i(TAG, "SignShape constructor");
        _handlerInitiate = false;
        _text = text;
        _userData = action;
        _square = new Square(yCenter,xCenter,height,width);
        _glSquare = new GLSquare(context, xCenter, yCenter, height, width, R.raw.sign);

    }

    /**
     * Return if the sign is touchable
     * @return true
     */
    @Override
    public boolean isTouchable() {
        return true;
    }

    /**
     * Set the different handler of the sign to the opengl
     * @param positionHandle
     * @param textureHandle
     * @param MVPMatrixHandle
     * @param vMatrix
     * @param projMatrix
     */
    public void setGLHandler(int positionHandle, int textureHandle, int MVPMatrixHandle,
                             float vMatrix[], float projMatrix[]){
        _glSquare.setGLHandler(positionHandle,textureHandle,MVPMatrixHandle,vMatrix,projMatrix, _text);
        _handlerInitiate = true;

    }

    /**
     * Draw the sign
     */
    @Override
    public void draw(){
        _glSquare.draw();
    }

    /**
     * Test if the input point touches the sign
     * @param touch the input point
     * @return
     */
    public boolean isTouched(Vec2 touch){
        if(_square.isTouched(touch)){
            Log.i(TAG, _text + " is touched.");
            return true;
        }
        return false;
    }

    /**
     * Test if the input point touches the sign
     * @param x the x coordinate of the input point
     * @param y the y coordinate of the input point
     * @return
     */
    public boolean isTouched(float x, float y){
        if(_square.isTouched(x, y)){
            Log.i(TAG, _text + " is touched.");
            return true;
        }
        return false;
    }

    public String toString(){
        return "\n glSquare: " + _glSquare.toString() + "\n square :" + _square.toString();
    }

    public Square getSquare(){
        return _square;
    }

    public GLSquare getGLSquare(){
        return _glSquare;
    }

    public void calculateNextCoordinate() {

    }
}
